package demo;

import java.io.BufferedReader;
import java.io.StringReader;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

import com.amarsoft.dexpre.ResourceConfig;
import com.amarsoft.dexpre.bean.Transaction;
import com.amarsoft.dexpre.parser.ServerDataParser;

public class Demo1DataParser extends ServerDataParser {
	
	protected Transaction createTransaction(Object receivedData) throws Exception{
		Transaction trans = null;
//		trans = ResourceConfig.getTransactionByCode("DEXPRE_TRANS_SERVER2"); 
		
		
		String tempXmlStr = new String((byte[])receivedData);
		BufferedReader sr = new BufferedReader(new StringReader(tempXmlStr));
		SAXBuilder b = new SAXBuilder();
		Document doc = b.build(sr);
		Element xRoot = doc.getRootElement();
		String serviceCode = xRoot.getChild("head").getChild("SERVICE_CODE").getValue();
		trans = ResourceConfig.getTransactionByServiceCode(serviceCode, deployID);
		return trans;
	}
	
}
